#include <Servo.h>
#include <SoftwareSerial.h>

/* Sets pin (10, 11) and (12, 13) as rx and tx for wheel control and linear actuator
   You can utilize any digital pins except (0,1) which are reserve for the USB.
   I believe the ports are always in pairs.*/
SoftwareSerial actuator = SoftwareSerial(10, 11);
SoftwareSerial wheels = SoftwareSerial(12, 13);
//Servo rooster;

void setup(){
  /* Instance name: sets transfer baudrate,
     the higher the number the faster the transfor speed.*/
  Serial.begin(9600);
  wheels.begin(9600);
  actuator.begin(9600);
  pinMode(9, OUTPUT);
 // rooster.attach(9);
 // rooster.write(95); // Turns Off Rooster
}

void loop(){
 if (Serial.available() > 0){
  int val = Serial.read();
    
    // M1(3;64;125), M2(130;192;253) (1-127, 128-255)
    if (val > 3 && val < 125 ){
      wheels.write(val);
    }
    else if (val > 130 && val < 253){
      wheels.write(val);
    }
    // Brush (1=ON, 2=OFF) 
    else if(val == 1){
     // rooster.write(0);
     analogWrite(9,0);
    }
    else if(val ==2){
    //  rooster.write(95);
    analogWrite(9,95);
    }
    // Small Actuator(126=Down, 127=Stop, 128=UP)
    else if(val == 126){
      actuator.write(1);
    }
    else if(val == 127){
      actuator.write(64);
    }
    else if(val == 128){
      actuator.write(127);
    }
    // Big Actuator(129=Down, 254=Stop, 255=UP)
    else if (val == 129){
      actuator.write(128);
    }
    else if (val == 254){
      actuator.write(192);
    }
    else if (val == 255){
      actuator.write(255);
    }
    else (Serial.println("NOTHING")); // For testing only
  }
}
      
  
